//
//  ext+UIView.swift
//  NewMicroblog
//
//  Created by apple on 2016/10/23.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

///MARK:- UIImageView
extension UIImageView{
    convenience init(imageName: String) {
        self.init()
        self.image = UIImage(named:imageName)
    }
    
    func my_setImage(urlStr:String?, placeholderImgName: String?){
        let url = URL(string: urlStr ?? "")
        guard let u = url else {
            return
        }
          self.sd_setImage(with: u, placeholderImage: UIImage(named: placeholderImgName ?? ""))
    }
    
}

extension UILabel {
    convenience init(title: String, fontSize: CGFloat,textColor: UIColor,axWidth: CGFloat = 0){
        self.init()
        self.textColor = textColor
        self.font = UIFont.systemFont(ofSize: fontSize)
        self.text = title
        if axWidth > 0 {
            self.preferredMaxLayoutWidth = axWidth
            self.numberOfLines = 0
        }
        }
    
    
}
extension UIView {
    
    //  扩展计算属性 -> 不能提供存储属性
    //  x坐标
    var x: CGFloat {
        get {
            return self.frame.origin.x
        } set {
            self.frame.origin.x = newValue
        }
    }
    
    //  y坐标
    var y: CGFloat {
        get {
            return self.frame.origin.y
        } set {
            self.frame.origin.y = newValue
        }
    }
    
    //  width宽度
    var width: CGFloat {
        get {
            return self.frame.size.width
        } set {
            self.frame.size.width = newValue
        }
    }
    //  height 高度
    var height: CGFloat {
        get {
            return self.frame.size.height
        } set {
            self.frame.size.height = newValue
        }
    }
    
    //  size 大小
    var size: CGSize {
        get {
            return self.frame.size
        } set {
            self.frame.size = newValue
        }
    }
    
    //  获取中心 x
    var centerX: CGFloat {
        get {
            return self.center.x
        } set {
            self.center.x = newValue
        }
    }
    
    //  获取中心 y
    var centerY: CGFloat {
        get {
            return self.center.y
        } set {
            self.center.y = newValue
        }
    }
    
    
}
